﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AnQinFrameWorkAPI.Migrations
{
    /// <inheritdoc />
    public partial class _202510311737 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "FinanceUser",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    Code = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Account = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Password = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Email = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    MobilePhone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FinanceUser", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "FinanceCategory",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    FinanceUserId = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    CategoryName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FinanceCategory", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FinanceCategory_FinanceUser_FinanceUserId",
                        column: x => x.FinanceUserId,
                        principalTable: "FinanceUser",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "FinanceUserAccount",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    FinanceUserId = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    AccountName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    AccountBalance = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FinanceUserAccount", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FinanceUserAccount_FinanceUser_FinanceUserId",
                        column: x => x.FinanceUserId,
                        principalTable: "FinanceUser",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "FinanceDetail",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    UserId = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    FinanceCategoryId = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    FinanceAccountId = table.Column<Guid>(type: "uniqueidentifier", maxLength: 36, nullable: false),
                    Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    TransactionTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Remark = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    Attachment = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    FinanceUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FinanceDetail", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FinanceDetail_FinanceCategory_FinanceCategoryId",
                        column: x => x.FinanceCategoryId,
                        principalTable: "FinanceCategory",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_FinanceDetail_FinanceUserAccount_FinanceAccountId",
                        column: x => x.FinanceAccountId,
                        principalTable: "FinanceUserAccount",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_FinanceDetail_FinanceUser_FinanceUserId",
                        column: x => x.FinanceUserId,
                        principalTable: "FinanceUser",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_FinanceCategory_FinanceUserId",
                table: "FinanceCategory",
                column: "FinanceUserId");

            migrationBuilder.CreateIndex(
                name: "IX_FinanceDetail_FinanceAccountId",
                table: "FinanceDetail",
                column: "FinanceAccountId");

            migrationBuilder.CreateIndex(
                name: "IX_FinanceDetail_FinanceCategoryId",
                table: "FinanceDetail",
                column: "FinanceCategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_FinanceDetail_FinanceUserId",
                table: "FinanceDetail",
                column: "FinanceUserId");

            migrationBuilder.CreateIndex(
                name: "IX_FinanceUserAccount_FinanceUserId",
                table: "FinanceUserAccount",
                column: "FinanceUserId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "FinanceDetail");

            migrationBuilder.DropTable(
                name: "FinanceCategory");

            migrationBuilder.DropTable(
                name: "FinanceUserAccount");

            migrationBuilder.DropTable(
                name: "FinanceUser");
        }
    }
}
